<template>
	<view>
		<head1-navigation :isBack="false">
			<block slot="content">微信绑定</block>
		</head1-navigation>
			
		<view class="bg-white text-center">
			<view class="text-xsl padding-lg">
				<text class="cuIcon-weixin text-green"></text>
				<text class="iconfont icon-huhuan text-yellow text-xl padding"></text>
				<text class="cu-avatar cu-avatar-auth xl round"></text>
			</view>
			<view class="grid margin-lg padding-lg text-center col-3 solids-bottom">
				<view class=""></view>
				<view class="text-center">
					<view class="text-grey text-lg">{{UserInfo.userName}}</view>
					<view class="text-grey text-xs margin-top-sm">ID:{{UserInfo.shareCode}}</view>
				</view>
				<view class=""></view>
			</view>
			
			<view class="padding" v-if="UserInfo.wxUnionid" >
				<view class="text-left padding-top">钰云(虾芒)小程序专属服务:</view>
				<view class="text-left padding text-grey">
					<view>1. 用户提现申请, 24小时内到账</view>
					<view>2. 在线客服, 解决用户操作疑问。</view>
				</view>
				<view class="bg-white flex flex-direction padding-tb-xl">
					<button @tap="openAccount" class="cu-btn bg-green text-white margin-sm lg">进入账户</button>
				</view>
			</view>
			
			<view class="padding" v-else >
				<view class="text-left padding-top">申请获取以下权限:</view>
				<view class="text-left padding text-grey">
					<view>1. 获得你的公开信息(昵称，头像、地区等)</view>
					<view>2. 获取你的收款账户(以便接收奖励收款)</view>
				</view>
				<view class="bg-white flex flex-direction padding-tb-xl">
					<button class="cu-btn bg-green text-white margin-sm lg" @tap="wxUserLogin">用户授权</button>
				</view>
			</view>

		</view>
		<model-userlogin></model-userlogin>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				UserInfo: {
					wxUnionid: false,
					userName: "请先登陆",
					userPhone: "请先登陆",
					shareCode: "R000000",
					usableMoney: "0.00",
					usableRbi: "0.00",
					avator: false
				},
			}
		},
		
		onLoad: function (e) {
			let _this = this;
			console.log("接收参数###", e);
				
			// 1. 添加登陆监听
			uni.$on("loginModel", (e)=>{
				_this.Http.isLogin = 'CLOSE';
				if('CLOSE' == e) {
					_this.getUserInfo();
				}
			});
			
			// 2. 用户状态缓存
			if(e.token) {
				uni.setStorage({key: 'authtoken', data: e.token,
					success: function () {
						_this.getUserInfo();
					}
				});
			}
		},
		
		methods: {
			
			// 用户信息
			getUserInfo() {
				let _this = this;
				
				// 发起请求
				_this.Http.post("my/user/info", {}, function(responseData) {
					console.log("用户信息", responseData);
					_this.UserInfo = responseData.returndata;
				});
			},
			
			/**
			 * 用户登陆
			 */
			wxUserLogin() {
                let _this = this;
				uni.$emit("loginModel", 'OPEN');
				// 回调函数
				// _this.getUserInfo();
            },

			
			/**
			 * 进行账户
			 */
			openAccount() {
                let _this = this;
				uni.reLaunch({
					url: "../../index"
				})
            }
			
		}
	}
</script>

<style>
	page {
		background-color: #FFFFFF;
	}

	.iconfont.icon-huhuan {
		font-size: 50rpx;
	}
	
	.solid-bottom.text-xsl {
		font-size: 100rpx;
	}
</style>
